
const app =getApp()

Component({
    /**
     * 组件的属性列表
     */
    properties: {
        'title' : {
            type : Boolean ,
            value : '' ,
        },
        'show':{
          type : Boolean ,
          value : true ,
        }
    },
    ready :function(){
       
    },
    /**
     * 组件的初始数据
     */
    data: {
        model_show:false,
        xProduct_list:[],
        userInfo:{},
        title:'',
        current_pid:'',
        show:true,
        anno_list:['减轻疼痛','缓解疲劳','提升身体机能','改善睡眠','改善情绪','减少医疗负担']
    },
    
    /**
     * 组件的方法列表
     */
    methods: {
        modelHidden:function(){
          let that =this;
          wx.reportEvent("event_cancel_analysis_product", {
            "key":false
          })
          that.setData({
            model_show:false
          })
        },
        xToResearch_model:function(){
          let that =this;
          that.setData({
            model_show:false
          })
          wx.reportEvent("event_go_analysis_product", {
            "key":true
          })
          wx.navigateTo({
            url: '/subuser/pages/improveData/index',
          })
        },
        xToProductOther:function(e){
          let name = e.currentTarget.dataset.name
          wx.navigateTo({
            url: '/subtool/pages/productother/index/index?name='+name,
          })
        },
        xToProductde:function(e){
          let that =this
          let params = e.currentTarget.dataset
          if(that.data.xProduct_list[params.index].is_required_evaluation ){
            wx.cloud.callFunction({
              name : 'user' ,
              data : {
                  action : 'detail'
              }
            }).then( res => {
              app.globalData.xCustomer = res.result
              app.globalData.user = res.result
              that.setData({
                userInfo:res.result,
                current_pid:params.id
              })
              if(!that.data.userInfo.hard_calm_down){
                that.setData({
                  model_show:true
                })
              }else{
                if(params.treatment_range_type==2){
                  wx.navigateTo({
                    url: '/subtool/pages/productother/index/index?name='+params.name,
                  })
                }else{
                  wx.navigateTo({
                    url: '/subsale/pages/product/index/index?id='+ params.id +'&time='+ params.date ,
                  })
                }
              }
            })
            
          }else{
            if(params.treatment_range_type==2){
              wx.navigateTo({
                url: '/subtool/pages/productother/index/index?name='+params.name,
              })
            }else{
              wx.navigateTo({
                url: '/subsale/pages/product/index/index?id='+ params.id +'&time='+ params.date ,
              })
            }
          }
          
        },
        // 获取产品/方案
        xGetProduct:function(){
          let that =this;
          wx.cloud.callFunction({
            name: 'product',
            data: {
                action: "get_digital_therapy_product"
              }
          }).then(res => {
            that.setData({
              xProduct_list:res.result
            })
          })
        }
        
    },
    // created:function(){
    //    this.xGetProduct()
    //   //  this.GetUserInfo()
    // },
    attached:function(){
      this.xGetProduct()
    }
})
